#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str;
    cin >> str;
    int left = 0;
    int ret = -1;
    while (left < str.size())
    {
        if (left + 1 < str.size() && str[left] == str[left + 1])
        {
            ret = 2;
            break;
        }
        else if (left + 2 < str.size() && str[left] == str[left + 2])
        {
            ret = 3;
        }
        left++;
    }
    cout << ret << endl;
    return 0;
}